import sys,os,cgi,time
sys.path.insert(0, os.path.split(sys.path[0])[0])

import cfg
import tag

query = os.getenv("QUERY_STRING",'') 
kwargs = cgi.parse_qs(query)
date = kwargs.get('date',[time.strftime("%Y%m%d")])[0]
job_name = kwargs.get('job',[''])[0].lower()
runid = kwargs.get('runid',[''])[0].lower()
fn = kwargs.get('fn',[''])[0].lower()

step_dir = cfg.get_step_log_dir(date,job_name)
path = os.path.join(step_dir,'run'+runid,fn)

if False:
	print "HTTP/1.1 200 ok"
	print "Content-Type: text/plain"
	print
else:
	import head
	head.header(banner=False,ct="text/plain",action='log',tags=tag.job_tags(job_name))

for line in open(path,'r').readlines():
	print line.rstrip()
